package com.nebula.api.modules.app.conctroller;

import cn.hutool.json.JSONUtil;
import com.nebula.api.common.cache.UserTokenInfo;
import com.nebula.api.common.entity.TokenUser;
import com.nebula.api.modules.app.service.AppUserService;
import com.nebula.commons.modules.form.LoginForm;
import com.nebula.commons.modules.system.entity.SysUser;
import link.ahsj.core.entitys.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Eastern unbeaten
 * @version 1.0
 * @date 2019/8/17 14:13
 * @mail chenshiyun2011@163.com
 */
@RestController
public class LoginController {

    @Autowired
    private UserTokenInfo userTokenInfo;
    @Autowired
    private AppUserService appUserService;

    /**
     * 用户登录
     */
//    @PostMapping(value = "/login")
//    public ResponseEntity<ApiModel> login(@RequestBody LoginForm loginForm) {
//        SysUser user = appUserService.login(loginForm);
//        TokenUser tokenUser = new TokenUser(user);
//        String token = userTokenInfo.generateUserToken(() -> JSONUtil.toJsonStr(tokenUser), user.getUsername());
//        return ResponseEntity.ok(ApiModel.data(token));
//    }
    @GetMapping(value = "/getUser")
    public ResponseEntity<ApiModel> getUser(TokenUser tokenUser) {
        return ResponseEntity.ok(ApiModel.data(tokenUser));
    }

}
